﻿
@{
    ViewBag.Title = "PersonWorkSpace";
    Layout = "~/Views/Shared/_LayoutForEUI.cshtml";
    var listColumns = ViewBag.Columns as List<SGArchiveSystem7x.Models.CColumnsModel>;
    var listColumnsQX = ViewBag.ColumnsQX as List<SGArchiveSystem7x.Models.CColumnsModel>;
    var Dept = ViewBag.dept as List<SGArchiveSystem7xDB.T_ArchiveTree>; 
    var listColumnsSP = ViewBag.ColumnsSP as List<SGArchiveSystem7x.Models.CColumnsModel>;
}

<div class="easyui-tabs" style="width:100%;height:100%" id="Insiders_PersonWorkSpace_tt">
    <div title="我的借阅" style="padding:10px">
        <table id="Insiders_PersonWorkSpace_grid" class="easyui-datagrid" style="width:100%;" title="借阅" data-options="
       rownumbers:true,
       singleSelect:true,
       autoRowHeight:false,
       pagination:true,
       fitColumns:true,
       fit:true,
       striped:true,
       checkOnSelect:false,
       selectOnCheck:false,
       toolbar:'#Insiders_PersonWorkSpace_tb',
       collapsible:false ,
               pageSize: @SGArchiveSystem7x.Models.CCommonsModels.PageSize ,
               pageList:[10,15,20]">
            <thead frozen="true">
                <tr>
                    @{foreach (var c in listColumns)
                        {
                            if (c.Frozen)
                            {
                                <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                            }

                        }
                    }
                </tr>
            </thead>
            <thead>
                <tr>
                    @{foreach (var c in listColumns)
                        {
                            if (!c.Frozen)
                            {
                                <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                            }

                        }
                    }
                </tr>
            </thead>
        </table>
        <div id="Insiders_PersonWorkSpace_tb" style="padding:2px 5px;">
            <input type="text" class="easyui-textbox" labelposition="right" label="借阅题名:" labelwidth="70px" style="width:180px" id="Insiders_PersonWorkSpace_txtTM" />
            <input type="text" class="easyui-datebox" data-options="editable:false" labelposition="right" label="借阅起始时间:" labelwidth="90px" style="width:190px" id="Insiders_PersonWorkSpace_txtSTime" />
            <input type="text" class="easyui-datebox" data-options="editable:false" labelposition="right" label="借阅结束时间:" labelwidth="90px" style="width:190px" id="Insiders_PersonWorkSpace_txtETime" />
            <select id="Insiders_PersonWorkSpace_cmbArchiveType" class="easyui-combobox" labelposition="right" label="档案类型：" data-options="editable:false" name="Insiders_PersonWorkSpace_cmbArchiveType" style="width:170px;" panelHeight="auto" editable="false">
                <option value="-1" selected="selected">全部</option>
                @{
                    foreach (var n in Dept)
                    {
                        <option value="@n.AR_ID">@n.AR_NAME</option>
                    }
                }
            </select>
            <select id="Insiders_PersonWorkSpace_cmbType" class="easyui-combobox" labelposition="right" label="借阅类型：" data-options="editable:false" name="Insiders_PersonWorkSpace_cmbType" style="width:170px;" panelHeight="auto" editable="false">
                <option value="-1" selected="selected">全部</option>
                <option value="1">电子借阅</option>
                <option value="2">纸质借阅</option>
            </select>
            <a href="javascript:void(0);" class="easyui-linkbutton button-blue" iconCls="icon-search" onclick="QUERY()" style="height: 30px;width:100px">查询</a>
        </div>
    </div>
    <div title="我的权限" style="padding:10px">
        <table id="ArchiveAuthority_DepartmentArchiveList_grid" class="easyui-datagrid" style="width:100%;" title="个人权限" data-options="
       rownumbers:true,
       singleSelect:true,
       autoRowHeight:false,
       pagination:false,
       fitColumns:true,
       fit:false,
       striped:true,
       checkOnSelect:false,
       selectOnCheck:false,
       toolbar:'#ArchiveAuthority_DepartmentArchiveList_tb',
       collapsible:false">
            <thead frozen="true">
                <tr>
                    @{foreach (var c in listColumnsQX)
                        {
                            if (c.Frozen)
                            {
                                <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                            }

                        }
                    }
                </tr>
            </thead>
            <thead>
                <tr>
                    @{foreach (var c in listColumnsQX)
                        {
                            if (!c.Frozen)
                            {
                                <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                            }

                        }
                    }
                </tr>
            </thead>
        </table>
    </div>
    <div title="审批流" style="padding:10px;" id="Insiders_PersonWorkSpace_divSPflow">
        <table id="SP_Index_grid" class="easyui-datagrid" style="width:100%;" title="审批" data-options="
       rownumbers:true,
       singleSelect:true,
       autoRowHeight:false,
       pagination:true,
       fitColumns:true,
       fit:true,
       striped:true,
       checkOnSelect:false,
       selectOnCheck:false,
       toolbar:'#SP_Index_tb',
       collapsible:false,
       pageSize: @SGArchiveSystem7x.Models.CCommonsModels.PageSize,
       pageList:[10,15,20]">
            <thead frozen="true">
                <tr>
                    <th data-options="field:'ck',checkbox:true"></th>
                    @{foreach (var c in listColumnsSP)
                        {
                            if (c.Frozen)
                            {
                                <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                            }

                        }
                    }
                </tr>
            </thead>
            <thead>
                <tr>
                    @{foreach (var c in listColumnsSP)
                        {
                            if (!c.Frozen)
                            {
                                <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                            }

                        }
                    }
                </tr>
            </thead>
        </table>
        <div id="SP_Index_tb" style="padding:2px 5px;">
            <a href="javascript:void(0);" id="SP_Index_btnAgree" class="easyui-linkbutton button-blue" iconCls="icon-redo" onclick="Agree(1)" style="width:110px;height:30px;">同意</a>
            <a href="javascript:void(0);" id="SP_Index_btnDis" class="easyui-linkbutton button-orange" iconCls="icon-redo" onclick="Agree(2)" style="width:110px;height:30px;">不同意</a>
        </div>
    </div>
</div>

<script>
        $(document).ready(function () {
            var type = $('#Insiders_PersonWorkSpace_cmbType').combobox('getValue');
            var Atype = $('#Insiders_PersonWorkSpace_cmbArchiveType').combobox('getValue');
            //alert(type);
            $('#ArchiveAuthority_DepartmentArchiveList_grid').datagrid({
                url: '/ArchiveAuthority/Get_ajaxDepartmentArchiveList?DepartmentId=' + @ViewBag.DepId,
                singleSelect: true,
                method: 'post',
                onLoadSuccess: function (data) {
                    $('.pagination-page-list').hide();
                }
            });
            $('#Insiders_PersonWorkSpace_grid').datagrid({
                url: '/Insiders/Get_ajaxPersonWorkSpaceArchive?type=' + type + '&Atype=' + Atype,
                //url: '/Insiders/Get_ajaxPersonWorkSpaceArchive',
                singleSelect: true,
                method: 'post',
                onLoadSuccess: function (data) {
                    $('.pagination-page-list').hide();
                }
            });
            $('#SP_Index_grid').datagrid({
                url: '/SP/Get_ajaxSPFlowArchive?depid=' + '@ViewBag.DepId',
                singleSelect: true,
                method: 'post',
                onLoadSuccess: function (data) {
                    $('.pagination-page-list').hide();
                }
            });
            if (@ViewBag.U_I01!= 1) {
                $('#Insiders_PersonWorkSpace_tt').tabs('getTab', "审批流").panel('options').tab.hide();
            }
            InitPagenation();
            InitPagenation1();
        });
        function QUERY() {
            var tm = $('#Insiders_PersonWorkSpace_txtTM').val();
            var type = $('#Insiders_PersonWorkSpace_cmbType').combobox('getValue');
            var Atype = $('#Insiders_PersonWorkSpace_cmbArchiveType').combobox('getValue');
            var stime = $('#Insiders_PersonWorkSpace_txtSTime').datebox('getValue');
            var etime = $('#Insiders_PersonWorkSpace_txtETime').datebox('getValue');
            $('#Insiders_PersonWorkSpace_grid').datagrid('options').url = '/Insiders/Get_ajaxPersonWorkSpaceArchive?tm=' + tm + '&type=' + type + '&Atype=' + Atype + '&stime=' + stime + '&etime=' + etime;
            $('#Insiders_PersonWorkSpace_grid').datagrid('load');
        }
        function formatDate(value, row) {
            if (value != null) {
                var time = new Date(parseInt(value.substr(6, 19)))//.toLocaleDateString();//13
                return time.getFullYear() + "-" + (time.getMonth() + 1) + "-" + time.getDate() + " " + time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds();
            }
            else {
                return "";
            }
        }
        function formatStatus(value, row) {
            if (value == 0) {
                return "申请";
            }
            else if (value == 1) {
                return "借出";
            }
            else {
                return "结束";
            }
        }
        function formatStatusI(value, row) {
            if (value == '0')
                return "<a hef='javascript:void(0);'><span style='color:red'>禁止</span></a>";
            else if (value == '1')
                return "<a hef='javascript:void(0);'><span style='color:blue'>允许</span></a>";
            else
                return "";
        }
        function formatSPValue(value, row) {
            if (value == 0) {
                return "未审批";
            }
            else if (value == 1) {
                return "通过";
            }
            else {
                return "拒绝";
            }
        }
        function formatType(value, row) {
            if (value == 1) {
                return "电子借阅";
            }
            else {
                return "纸质借阅";
            }
        }
        function formatYQTS(value, row) {
            if (value == 0) {
                return "";
            }
            else {
                return value;
            }
        }
        function formatFile(value, row) {
            var dh = row.BI_DH;
            var type = row.BU_TYPE;
            var status = row.BI_STATUS;
            return "<a href='javascript:void(0)' onclick='showPdf(\"" + dh + "\",\"" + type + "\",\"" + status + "\")'><img src='../Content/images/images.png'></img></a>";
        }
        function showPdf(value, type, status) {
            //alert(id);
            if (type == 1 && status == 1) {
                $.ajax({
                    url: '/Insiders/pdfpath',
                    dataType: "text",
                    type: "post",
                    data: { 'dh': value },
                    success: function (data) {
                        if (data != "1") {
                            window.open('../../Content/generic/web/viewer.html?file=' + data + "&down=0&print=0");
                        }
                        else { $.messager.alert('提示！', '出错或电子文件不存在!', 'info'); }
                    }
                });
            }
            else { $.messager.alert('提示！', '只有电子借阅并审批同意的才能查看电子文件!', 'info'); }
        }
        function formatSPStatus(value, row) {
            if (value == 0) {
                return "未审批";
            }
            else if (value == 1) {
                return "已审批";
            }
            else if (value == 2) {
                return "流程中(本部门审批)";
            }
            else {
                return "流程中(归档部门审批)";
            }
    }
    function formatJYSP(value, row) {
       // var id = row.BI_ID;
        return "";
    }
    function InitPagenation() {
        //设置分页控件
        var p = $('#Insiders_PersonWorkSpace_grid').datagrid('getPager');
        $(p).pagination({
            onSelectPage: function (pageNumber, pageSize) {
                QueryPager(pageNumber, pageSize);
            }
        });
    }
    ///分页查询
    function QueryPager(num, size) {
        $('#Insiders_PersonWorkSpace_grid').datagrid('options').url = '/Insiders/Get_ajaxPersonWorkSpaceArchivePager?num=' + num + '&size=' + size;
        $('#Insiders_PersonWorkSpace_grid').datagrid('reload');
        $('#Insiders_PersonWorkSpace_grid').datagrid('options').pageNumber = num;
        $('#Insiders_PersonWorkSpace_grid').datagrid('options').pageSize = size;
        return;
    }
        function Agree(result)
    {
        var rows = $('#SP_Index_grid').datagrid('getChecked');
        if (rows.length == 0) {
            $.messager.alert('提示！', '请选择要审批的档案!', 'info');
            return false;
        }
        else {
            var suggest = "";
            if (result == 2) {
                $.messager.prompt('提示', '请输入审批意见', function (r) {
                    if (r) {
                        suggest = r;
                        var id = [];
                        for (var i = 0; i < rows.length; i++) {
                            id.push(rows[i].SPF_ID);
                        }
                        $.ajax({
                            url: '/SP/FlowSP',
                            type: 'post',
                            dataType: 'json',
                            data: { 'result': result, 'id': id, 'suggest': suggest },
                            success: function (data) {
                                $.messager.alert('提示', '审批成功', 'info');
                                $('#SP_Index_grid').datagrid('options').url = '/SP/Get_ajaxSPFlowArchive?depid=' + '@ViewBag.DepId',
                                    $('#SP_Index_grid').datagrid('load');
                            }
                        });
                    }
                });
            }
            else {
                var id = [];
                for (var i = 0; i < rows.length; i++) {
                    id.push(rows[i].SPF_ID);
                }
                $.ajax({
                    url: '/SP/FlowSP',
                    type: 'post',
                    dataType: 'json',
                    data: { 'result': result, 'id': id, 'suggest': suggest },
                    success: function (data) {
                        $.messager.alert('提示', '审批成功', 'info');
                        $('#SP_Index_grid').datagrid('options').url = '/SP/Get_ajaxSPFlowArchive?depid=' + '@ViewBag.DepId',
                            $('#SP_Index_grid').datagrid('load');
                    }
                });
            }
        }
    }

    function formatStage(value, row) {
        if (value == 1) {
            return "本部门审批";
        }
        else if (value == 2) {
            return "档案归档部门审批";
        }
        else { return "";}
    }
    ///初始化分页
    function InitPagenation1() {
        //设置分页控件
        var p = $('#SP_Index_grid').datagrid('getPager');
        $(p).pagination({
            onSelectPage: function (pageNumber, pageSize) {
                QueryPager1(pageNumber, pageSize);
            }
        });
    }
    ///分页查询
    function QueryPager1(num, size) {
        $('#SP_Index_grid').datagrid('options').url = '/SP/Get_ajaxSPFlowArchivePager?num=' + num + '&size=' + size;
        $('#SP_Index_grid').datagrid('reload');
        $('#SP_Index_grid').datagrid('options').pageNumber = num;
        $('#SP_Index_grid').datagrid('options').pageSize = size;
        return;
    }
</script>




